/*My Web Server 
 *Bhojan Anand
 */


import java.util.*;
import java.io.*;
import java.net.*;

public class Search_WebServer {
	
	static Search_engine search_engine;
	
	
    public static void main (String args[]) throws Exception 
	{
		// throws Exception here because don't want to deal
		// with errors in the rest of the code for simplicity.
		
		// Create a new TCP WELCOME SOCKET that waits for connection at port
		// number 9000.
    	search_engine = new Search_engine();
		ServerSocket serverSock = new ServerSocket(7000);
		System.out.println("SERVER IS WAITING FOR HTTP REQUEST at PORT 7000...");
		
		while (true) 
		{
			//Listen & Accept Connection and Create new CONNECTION SOCKET
			Socket s = serverSock.accept();
				
			//Construct an instance of HttpRequestProcessor to process this request
			HttpRequestProcessor reqProcessor = new HttpRequestProcessor(s,search_engine);
			
			//Create a new thread to process the request
			Thread thread = new Thread(reqProcessor);
			
			//Start the thread.
			thread.start();		
		
		}
	}
}
